/* 题目：图形面积计算

描述：设计一个基于C++面向对象编程的程序，用于计算不同类型的图形的面积。要求使用多态和模板技术。
要求：
1. 定义一个基类`Shape`，包含一个纯虚函数`area()`，用于计算图形的面积。
2. 定义两个派生类`Rectangle`和`Circle`，分别用于表示矩形和圆形。这两个类都需要实现`area()`函数。
3. 定义一个模板函数`calculateTotalArea`，接受一个`Shape`指针的容器，计算容器内所有图形的总面积。
示例：
```cpp
int main() {
    std::vector<Shape*> shapes;
    shapes.push_back(new Rectangle(3, 4));
    shapes.push_back(new Circle(5));

    double totalArea = calculateTotalArea(shapes);
    std::cout << "Total area: " << totalArea << std::endl;

    return 0;
}
```

输出：
```
Total area: 78.5398
``` */

#include <iostream>
#include <vector>

class Shape
{
public:
    virtual ~Shape() 
    {

    }
    virtual double area() const = 0;

};
class Rectangle : public Shape
{
public: 
    Rectangle(double w, double h) : width(w), height(h) {} 
    double area() const override 
    {
        return width * height; 
    }     
private: 
    double width, height; 
};

class Circle : public Shape
{
private: 
    double radius; public: Circle(double r) : radius(r) {} 
    double area() const override { return M_PI * radius * radius; } 
};

template<typename Container> 
double calculateTotalArea(const Container& shapes) 
{ 
    double totalArea = 0.0; 
    for (const auto& shape : shapes) 
    { 
        totalArea += shape->area(); 
    } return totalArea; 
} 

int main()
{
    std::vector<Shape*> shapes;
    shapes.push_back(new Rectangle(3, 4));
    shapes.push_back(new Circle(5));

    double totalArea = calculateTotalArea(shapes);
    std::cout << "Total area: " << totalArea << std::endl;

    return 0;

}